import java.util.Stack;

/**
 * @author LKQ
 * @date 2021/12/27 15:07
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] heights = {10, 6, 8, 5, 11, 9};
        solution.canSeePersonsCount(heights);
    }

    public int[] canSeePersonsCount(int[] heights) {
        int n = heights.length;
        int[] ans = new int[n];
        Stack<Integer> stack = new Stack<>();
        for (int i = n - 1; i >= 0; i--) {
            while (!stack.isEmpty()) {
                ++ans[i];
                if (heights[i] > heights[stack.peek()]) {
                    stack.pop();
                }else {
                    break;
                }
            }
            stack.push(i);
        }
        return ans;
    }

}
